Skip to content

chore: reduce binary size with upx#212

Merged
mdelapenya merged 2 commits into
testcontainers:mainfrom
mdelapenya:reduce-size
Sep 26, 2025
Merged

chore: reduce binary size with upx#212
mdelapenya merged 2 commits into
testcontainers:mainfrom
mdelapenya:reduce-size

Conversation

@mdelapenya
Copy link
Copy Markdown
Member

@mdelapenya mdelapenya commented Sep 1, 2025

What does this PR do?

It uses upx to optimise the final Go binary.

I explored it on https://github.com/testcontainers/helloworld, and applied all the knowledge from that here.

Why is it important?

Instead of producing a Docker image with 10MB, we are producing one with ~5MB

@mdelapenya mdelapenya added chore Changes that do not impact the existing functionality docker Pull requests that update Docker code labels Sep 1, 2025
@mdelapenya mdelapenya self-assigned this Sep 1, 2025
Copy link
Copy Markdown
Member

@kiview kiview left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have numbers on startup impact?

Context, I believe for normal users (i.e. not CI), smaller images are less important than fast startup times. Depends on the accumulated values, but my hunch is, we don't want to make this trade.

Copy link
Copy Markdown
Member

@kiview kiview left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've let Copilot crunch the numbers on this in #213.

The TLDR is (which I admittedly might trust too blindly, but isn't that the name of the game nowadays? 😅):

UPX provides net benefits when: (Pull Time Savings × Pulls) > (Startup Overhead × Starts)

With 3.9 second pull savings vs 0.1ms startup overhead (100-iteration average), UPX is beneficial in virtually all real-world scenarios where containers are pulled more than once per 39,000 starts.

Given that we see Ryuk being pulled up to 19M times per month, we end up with real world savings of 95 TB per month!

Edit:
Above numbers don't consider savings we get on the bigger images, through HTTP transport compression 😉

@mdelapenya mdelapenya merged commit b3726af into testcontainers:main Sep 26, 2025
9 checks passed
@mdelapenya mdelapenya deleted the reduce-size branch September 26, 2025 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Changes that do not impact the existing functionality docker Pull requests that update Docker code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants